//
//  MineChatModel.swift
//  Exchange
//
//  Created by rui on 2018/5/8.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit


///头像距离两边的距离
let iconMargin: CGFloat = 16
let iconTopMargin: CGFloat = 5

let iconW: CGFloat = 40
let iconH: CGFloat = 40
///气泡展示的宽度
let minBubW: CGFloat = 50
///气泡展示的高度
let minBubH: CGFloat = 50

///文案距离气泡的内边距
let textMargin: CGFloat = 10
///气泡尖角的宽度
let bubMargin: CGFloat = 10

enum ChatModelUserType: Int {
    case me
    case friend
    case system
}

enum ChatModelType: Int {
    case text
    case time
    case system
}

let kChatTextFont = UIFont.systemFont(ofSize: 14.0)

class ChatModel: NSObject {
    var cellHeight: CGFloat = 0
    var modelType: ChatModelType = .text
    var userType: ChatModelUserType = .me
    
    var avatar: String?

    var time: TimeInterval?
    var timeStr: String?
    var text: String?

    override init() {
        super.init()
    }
    
    func updateHeight() {
        var height:CGFloat = 15
        let w = 2 * (iconMargin + textMargin + iconW) + bubMargin
        if modelType == .text {
            let size = text?.ch_sizeWithConstrained(kChatTextFont, constraintRect: CGSize(width: kSCREEN_WIDTH - w, height: CGFloat.greatestFiniteMagnitude)) ?? CGSize.zero
            height = size.height <= (minBubH - 2 * textMargin)  ? minBubH : (size.height + 2 * textMargin)
        }else if modelType == .system {
            let size = text?.ch_sizeWithConstrained(kChatTextFont, constraintRect: CGSize(width: kSCREEN_WIDTH, height: CGFloat.greatestFiniteMagnitude)) ?? CGSize.zero
            height = max(size.height, height)
        }
        height += iconTopMargin * 2
        cellHeight = height
    }
}

